package org.jeecg.modules.approve.free.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.approve.free.entity.BikeApproveFreeCharge;
import org.jeecg.modules.approve.free.service.IBikeApproveFreeChargeService;

import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.approve.free.vo.BikeApproveFreeChargeRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 免单审批信息
 * @Author: 月月鸟
 * @Date:   2021-07-15
 * @Version: V1.0
 */
@Api(tags="免单审批信息")
@RestController
@RequestMapping("/free/bikeApproveFreeCharge")
@Slf4j
public class BikeApproveFreeChargeController extends JeecgController<BikeApproveFreeCharge, IBikeApproveFreeChargeService> {
	@Autowired
	private IBikeApproveFreeChargeService bikeApproveFreeChargeService;

	/**
	 * 分页列表查询
	 *
	 * @param bikeApproveFreeCharge
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="免单审批信息-分页列表查询", notes="免单审批信息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(BikeApproveFreeChargeRes bikeApproveFreeCharge,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		return bikeApproveFreeChargeService.queryPageList(bikeApproveFreeCharge,pageNo,pageSize);
	}

	/**
	 *   添加
	 *
	 * @param bikeApproveFreeCharge
	 * @return
	 */
	@AutoLog(value = "免单审批信息-添加")
	@ApiOperation(value="免单审批信息-添加", notes="免单审批信息-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody BikeApproveFreeCharge bikeApproveFreeCharge) {
		bikeApproveFreeChargeService.save(bikeApproveFreeCharge);
		return Result.OK("添加成功！");
	}


	/**
	 *  审批
	 *
	 * @param bikeApproveFreeCharge
	 * @return
	 */
	@AutoLog(value = "免单审批信息-审批",operateType = 3)
	@ApiOperation(value="免单审批信息-审批", notes="免单审批信息-审批")
	@PutMapping(value = "/approve")
	public Result<?> approve(@RequestBody BikeApproveFreeCharge bikeApproveFreeCharge) {

		return bikeApproveFreeChargeService.approve(bikeApproveFreeCharge);
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "免单审批信息-通过id删除")
	@ApiOperation(value="免单审批信息-通过id删除", notes="免单审批信息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		bikeApproveFreeChargeService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "免单审批信息-批量删除")
	@ApiOperation(value="免单审批信息-批量删除", notes="免单审批信息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bikeApproveFreeChargeService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="免单审批信息-通过id查询", notes="免单审批信息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		BikeApproveFreeCharge bikeApproveFreeCharge = bikeApproveFreeChargeService.getById(id);
		if(bikeApproveFreeCharge==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(bikeApproveFreeCharge);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param bikeApproveFreeCharge
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, BikeApproveFreeCharge bikeApproveFreeCharge) {
        return super.exportXls(request, bikeApproveFreeCharge, BikeApproveFreeCharge.class, "免单审批信息");
    }

}
